package Servicio;

import java.net.InetAddress;
import java.rmi.*;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;

import Remoto.IGestionRodamientos;

public class BS {
    
    public void publicarServicio() 
    {
    	try 
    	{
    		IGestionRodamientos gestion = new GestionRodamientos();
    		IGestionRodamientos stub = (IGestionRodamientos) UnicastRemoteObject.exportObject(gestion, 0);
			LocateRegistry.createRegistry(Registry.REGISTRY_PORT);
			Naming.rebind("//localhost/GestionRodamientos", stub);
            verVinculos();
		} 
    	catch (Exception e) 
    	{
			e.printStackTrace();
		}
    }
   
    
    public void verVinculos() 
    {
        try 
        {
      	  String[] vinculos = Naming.list( "" );
      	  System.out.println(InetAddress.getLocalHost().getHostAddress());
      	  for ( int i = 0; i < vinculos.length; i++ )
      	  {
      		System.out.print( "\n"+vinculos[i] );
      	  }
      	  System.out.print( ">>> Servicio publicado");
        }
        catch (Exception e) 
        {
      	  e.printStackTrace();
        }
     }
    
    public void cerrar() 
    {
		try 
		{
			Naming.unbind("GestionRodamientos");
		} 
		catch (Exception e) 
		{
			
		} 
		finally 
		{
			System.exit(0);
		}
    }
}
